------------------------------------------------------------------------
--  Get reference for prototype
------------------------------------------------------------------------
local LibStub = _G.LibStub
local BarPlug = LibStub("AceAddon-3.0"):GetAddon("BarPlug")

------------------------------------------------------------------------
--  upvalues
------------------------------------------------------------------------
local setmetatable = _G.setmetatable
local pairs = _G.pairs

------------------------------------------------------------------------
--  Plugin handling
------------------------------------------------------------------------
local plugins = {}
local plugintable = BarPlug.plugintable
function BarPlug:NewPlugin(event, name, dataobj)
	if plugins[name] then
		return plugins[name]
	end

	-- Create plugin
	local plugin = setmetatable({
		name    = "BarPlug"..name,
		objname = name,
		dataobj = dataobj,
		enabled = false,
		owner	= BarPlug.panel,
		parent	= BarPlug.panel.frame,
		db 		= {}	-- FIXME Add db for each plugin
	}, plugintable)
	-- Init plugin
	plugin:Initialize()
	-- Enable plugin
	plugin:Enable()

	plugins[name] = plugin
	return plugin
end

function BarPlug:EnablePlugin(name)
	if plugins[name] then 
		plugins[name]:Enable() 
	end
end

function BarPlug:DisablePlugin(name)
	if plugins[name] then 
		plugins[name]:Disable() 
	end
end

function BarPlug:GetPlugin(name)
	if plugins[name] then 
		return plugins[name] 
	end
end

function BarPlug:IteratePlugins()
	return pairs(plugins)
end
